package com.geralt.im.server;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import com.geralt.im.jms.MessageQueueConsumer;
import com.geralt.im.jms.QueueMessageListener;
import com.geralt.im.model.NeedReplyMessage;

public class IMServerClient {
	public static IMServer server;
	public static void main(String[] args) {
		BlockingQueue <NeedReplyMessage> requstQueue = new LinkedBlockingQueue<NeedReplyMessage>();
		Properties props = new Properties();
		InputStream is = IMServer.class.getClassLoader().getResourceAsStream("Queue.properties");
		try {
			props.load(is);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String url = props.getProperty("url");
		String queue = props.getProperty("queue");
		MessageQueueConsumer consumer = new MessageQueueConsumer(url,queue);
		QueueMessageListener listener = new QueueMessageListener();
		listener.setMessageQueue(requstQueue);
		consumer.setListener(listener);
		consumer.beginListen();
		ServerCommandControler serverCommandControler = new ServerCommandControler();
		serverCommandControler.setRequstQueue(requstQueue);
		new Thread(serverCommandControler).start();
		server = new IMServer();
		server.start();
	}
}
